<?php
namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use App\Libs\Common\CsvUtil;
use App\Logics\OrderStagesLogic;

class OrderStagesController extends BaseController{
    private function getInstance(){
        static $ob=null;
        if($ob===null){
            $ob=new OrderStagesLogic();
        }
        return $ob;
    }

    //分期明细
    public function index(){
        $page = (int)request("page", 1);
        $per_page = (int)request("per_page", 20);

        $order_status=(int)request('order_status',-1);
        $order_comefrom =trim(request('order_comefrom'));
        $order_id=trim(request('order_id'));
        $goods_name=trim(request('goods_name'));
        $user_phone=trim(request('user_phone'));
        $user_name=trim(request('user_name'));
        $start_time=trim(request('start_time',''));
        $end_time=trim(request('end_time',''));

        $para=[
            'page'=>$page,
            'per_page'=>$per_page,
            'order_status'=>$order_status,
            'order_comefrom'=>$order_comefrom,
            'order_id'=>$order_id,
            'goods_name'=>$goods_name,
            'user_phone'=>$user_phone,
            'user_name'=>$user_name,
            'start_time'=>$start_time,
            'end_time'=>$end_time
        ];
        $ob=$this->getInstance();
        $data=$ob->index($para);
        if($data && is_string($data)) die(json_error($data));


        $content= view("admin.orderStages.index",$data) ;
        $data=[
            'content'=>$content,
            'header'=>'订单租期列表',
        ];
        return  $this->baseList($data);
    }


    //订单还款
    public function huanKuanOrders(){
        $page = (int)request("page", 1);
        $per_page = (int)request("per_page", 20);

        $order_status=(int)request('order_status',-1);
        $order_comefrom =trim(request('order_comefrom'));
        $order_id=trim(request('order_id'));
        $goods_name=trim(request('goods_name'));
        $user_phone=trim(request('user_phone'));
        $user_name=trim(request('user_name'));
        $start_time=trim(request('start_time',''));
        $end_time=trim(request('end_time',''));
        $daochu=(int)request('daochu',0);



        $para=[
            'page'=>$page,
            'per_page'=>$per_page,
            'order_status'=>$order_status,
            'order_comefrom'=>$order_comefrom,
            'order_id'=>$order_id,
            'goods_name'=>$goods_name,
            'user_phone'=>$user_phone,
            'user_name'=>$user_name,
            'start_time'=>$start_time,
            'end_time'=>$end_time,
            'daochu'=>$daochu
        ];
        $ob=$this->getInstance();
        $data=$ob->huanKuanOrders($para);
        if($data && is_string($data)) die(json_error($data));
        $content= view("admin.orderStages.huanKuanOrders",$data) ;
        $data=[
            'content'=>$content,
            'header'=>'订单还款列表',
        ];
        return  $this->baseList($data);
    }

    public function orderStagesExcel(){

        $order_status=(int)request('order_status',-1);
        $order_comefrom =trim(request('order_comefrom'));
        $order_id=trim(request('order_id'));
        $goods_name=trim(request('goods_name'));
        $user_phone=trim(request('user_phone'));
        $user_name=trim(request('user_name'));
        $start_time=trim(request('start_time',''));
        $end_time=trim(request('end_time',''));

        $para=[
            'order_status'=>$order_status,
            'order_comefrom'=>$order_comefrom,
            'order_id'=>$order_id,
            'goods_name'=>$goods_name,
            'user_phone'=>$user_phone,
            'user_name'=>$user_name,
            'start_time'=>$start_time,
            'end_time'=>$end_time,
        ];
        $ob=$this->getInstance();
        $data=$ob->orderStagesExcel($para);
        if($data && is_string($data)) die(json_error($data));
    }

    //订单分期账单列表
    public function orderStagesList(){
        $order_id=trim(request('order_id'));

        $ob=$this->getInstance();
        $data=$ob->getOrderStagesListByOrderId($order_id);
        if($data && is_string($data)) die(json_error($data));

        $content= view("admin.orderStages.orderStagesList",['data'=>$data]) ;
        $data=[
            'content'=>$content,
            'header'=>'订单分期列表',
        ];
        return  $this->frameList($data);
    }









}